package com.example.demo.service.impl;

import com.example.demo.entity.ShopInfo;
import com.example.demo.dao.ShopInfoDao;
import com.example.demo.service.ShopInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 店铺信息(ShopInfo)表服务实现类
 *
 * @author makejava
 * @since 2022-01-12 18:21:22
 */
@Service("shopInfoService")
public class ShopInfoServiceImpl implements ShopInfoService {
    @Resource
    private ShopInfoDao shopInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShopInfo queryById(Integer id) {
        return this.shopInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param shopInfo    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShopInfo> queryByPage(ShopInfo shopInfo, PageRequest pageRequest) {
        long total = this.shopInfoDao.count(shopInfo);
        return new PageImpl<>(this.shopInfoDao.queryAllByLimit(shopInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shopInfo 实例对象
     * @return 实例对象
     */
    @Override
    public ShopInfo insert(ShopInfo shopInfo) {
        this.shopInfoDao.insert(shopInfo);
        return shopInfo;
    }

    /**
     * 修改数据
     *
     * @param shopInfo 实例对象
     * @return 实例对象
     */
    @Override
    public ShopInfo update(ShopInfo shopInfo) {
        this.shopInfoDao.update(shopInfo);
        return this.queryById(shopInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.shopInfoDao.deleteById(id) > 0;
    }
}
